package edu.wisc.hevea.util;

import java.util.Date;

public class CommonUtil {

	private static final long SCALING_WINDOW_SECONDS = 60;
	private static final long BOOT_TIME_SECONDS = 60;
	private static final long CONSUMER_BOOT_TIME_SECONDS = 30;

	public static boolean canInitiateScalingAfterBoot(Date bootTime,
			Date currentTime) {
		long secondsBetween = (currentTime.getTime() - bootTime.getTime()) / 1000;
		return secondsBetween > BOOT_TIME_SECONDS;
	}

	public static boolean canInitiateScaling(Date lastScaledTime,
			Date currentTime) {
		long secondsBetween = (currentTime.getTime() - lastScaledTime.getTime()) / 1000;
		return secondsBetween > SCALING_WINDOW_SECONDS;
	}

	public static boolean canInitiateScalingForConsumer(Date lastScaledTime,
			Date currentTime) {
		long secondsBetween = (currentTime.getTime() - lastScaledTime.getTime()) / 1000;
		return secondsBetween > CONSUMER_BOOT_TIME_SECONDS;
	}
}
